#include "BattleCreator.h"



BattleCore* BattleCreator::createBattleCore(const char* data, unsigned int size)
{
	battle2::S2C_Start message;
	message.ParseFromArray(data, size);

	//for (size_t i = 0; i<message.desc().units().size(); i++) {
	//	auto unit = message.desc().units().Get(i);
	//	unit = unit;
	//}

	//for (size_t i = 0; i < message.desc().summonunits().size(); i++) {
	//	auto summonUnit = message.desc().summonunits().Get(i);
	//	int npcId = summonUnit.mask().characterid();
	//	printf("summonunit id: %d \n", npcId);
	//}

	//for (size_t i = 0; i < message.desc().groups().size(); i++) {
	//	auto group = message.desc().groups().Get(i);
	//	printf("desc.groups index:%d ,groupId: %d \n", i, group.groupid());
	//	for (size_t j = 0; j < group.npcid().size(); j++) {
	//		auto npcID = group.npcid().Get(j);
	//		printf("desc.groups npcId:%d \n", npcID);
	//	}
	//}

	auto rv = BattleCore::create(message.desc());
	return rv;
}

BattleCore* BattleCreator::createBattleCoreByDesc(const char* data, unsigned int size)
{
	battle2::BattleDesc desc;
	desc.ParseFromArray(data, size);

	for (size_t i = 0; i < desc.units().size(); i++) {
		auto unit = desc.units().Get(i);
		unit = unit;
	}

	auto rv = BattleCore::create(desc);
	return rv;
}

BattleCore* BattleCreator::createBattleCoreBySingleStart(const char* data, unsigned int size)
{
    battle2::S2C_SingleBattleStart message;
    message.ParseFromArray(data, size);

    for (size_t i = 0; i < message.desc().units().size(); i++) {
        auto unit = message.desc().units().Get(i);
        unit = unit;
    }

    auto rv = BattleCore::create(message.desc());
    return rv;
}

BattleCore* BattleCreator::createBattleCoreByQuickBattle(const char* data, unsigned int size)
{
	battle2::S2C_QuickBattle message;
	message.ParseFromArray(data, size);

	for (size_t i = 0; i < message.desc().units().size(); i++) {
		auto unit = message.desc().units().Get(i);
		unit = unit;
	}

	auto rv = BattleCore::create(message.desc());
	rv->createUnitsByDesc(rv->lastState());
	return rv;
}